package com.shujia.scala

import scala.collection.mutable
import scala.collection.mutable.ListBuffer

object Demo27MuTable {
  def main(args: Array[String]): Unit = {
    /**
      * 可变list
      *
      * listBuffer: 拥有list所有的方法，同时可以修改
      *
      */
    val listBuffer = new ListBuffer[String]

    //增加一个元素
    listBuffer.+=("java")

    //简写
    listBuffer += "spark"

    listBuffer += "spark"

    //批量插入元素
    listBuffer ++= List("1", "2", "3")

    println(listBuffer)

    //修改
    listBuffer(0) = "hadoop"

    println(listBuffer)

    //删除一个元素
    listBuffer -= "spark"
    //批量删除
    listBuffer --= List("1", "2")

    println(listBuffer)


    /**
      * 可变Map
      *
      */
    val hashMap = new mutable.HashMap[String, String]()


    //增加元素
    hashMap.put("001", "张三")

    hashMap.+=(("002", "李四"))

    //简写
    hashMap += "003" -> "王五"

    println(hashMap)

    //删除元素
    hashMap.remove("001")
    hashMap -= "002"

    //修改
    hashMap += "003" -> "王五1"
    println(hashMap)


    /**
      * 可变Set
      * 不可变set有的方法可变set都有
      *
      */

    val hashSet = new mutable.HashSet[String]()

    //增加元素
    hashSet.add("java")

    hashSet += "hadoop"
    hashSet += "hadoop"
    hashSet += "spark"
    hashSet ++= List("1", "2", "3")

    println(hashSet)

    //删除元素
    hashSet.remove("java")
    hashSet -= "hadoop"

    println(hashSet)


  }

}
